var $dp, WdatePicker;
(function() {
	var k = {
		$langList: [{
			name: "en",
			charset: "UTF-8"
		}, {
			name: "zh-cn",
			charset: "gb2312"
		}, {
			name: "zh-tw",
			charset: "GBK"
		}],
		$skinList: [{
			name: "default",
			charset: "gb2312"
		}, {
			name: "whyGreen",
			charset: "gb2312"
		}, {
			name: "blue",
			charset: "gb2312"
		}, {
			name: "green",
			charset: "gb2312"
		}, {
			name: "simple",
			charset: "gb2312"
		}, {
			name: "ext",
			charset: "gb2312"
		}, {
			name: "blueFresh",
			charset: "gb2312"
		}, {
			name: "twoer",
			charset: "gb2312"
		}, {
			name: "YcloudRed",
			charset: "gb2312"
		}],
		$wdate: true,
		$crossFrame: true,
		$preLoad: false,
		$dpPath: "",
		doubleCalendar: false,
		enableKeyboard: true,
		enableInputMask: true,
		autoUpdateOnChanged: null,
		weekMethod: "ISO8601",
		position: {},
		lang: "auto",
		skin: "default",
		dateFmt: "yyyy-MM-dd",
		realDateFmt: "yyyy-MM-dd",
		realTimeFmt: "HH:mm:ss",
		realFullFmt: "%Date %Time",
		minDate: "1900-01-01 00:00:00",
		maxDate: "2099-12-31 23:59:59",
		startDate: "",
		alwaysUseStartDate: false,
		yearOffset: 1911,
		firstDayOfWeek: 0,
		isShowWeek: false,
		highLineWeekDay: true,
		isShowClear: true,
		isShowToday: true,
		isShowOK: true,
		isShowOthers: true,
		readOnly: false,
		errDealMode: 0,
		autoPickDate: null,
		qsEnabled: true,
		autoShowQS: false,
		opposite: false,
		hmsMenuCfg: {
			H: [1, 6],
			m: [5, 6],
			s: [15, 4]
		},
		opposite: false,
		specialDates: null,
		specialDays: null,
		disabledDates: null,
		disabledDays: null,
		onpicking: null,
		onpicked: null,
		onclearing: null,
		oncleared: null,
		ychanging: null,
		ychanged: null,
		Mchanging: null,
		Mchanged: null,
		dchanging: null,
		dchanged: null,
		Hchanging: null,
		Hchanged: null,
		mchanging: null,
		mchanged: null,
		schanging: null,
		schanged: null,
		eCont: null,
		vel: null,
		elProp: "",
		errMsg: "",
		quickSel: [],
		has: {},
		getRealLang: function() {
			var b = k.$langList;
			for (var a = 0; a < b.length; a++) {
				if (b[a].name == this.lang) {
					return b[a]
				}
			}
			return b[0]
		}
	};
	WdatePicker = i;
	var e = window,
		j = {
			innerHTML: ""
		},
		q = "document",
		w = "documentElement",
		ab = "getElementsByTagName",
		h, ad, l, x, ae, f = navigator.appName;
	if (f == "Microsoft Internet Explorer") {
		l = true
	} else {
		if (f == "Opera") {
			ae = true
		} else {
			x = true
		}
	}
	ad = k.$dpPath || u();
	h = e;
	if (k.$crossFrame) {
		try {
			while (h.parent != h && h.parent[q][ab]("frameset").length == 0) {
				h = h.parent
			}
		} catch (p) {}
	}
	if (!h.$dp) {
		h.$dp = {
			ff: x,
			ie: l,
			opera: ae,
			status: 0,
			defMinDate: k.minDate,
			defMaxDate: k.maxDate
		}
	}
	ac();
	if (k.$preLoad && $dp.status == 0) {
		z(e, "onload", function() {
			i(null, true)
		})
	}
	if (!e[q].docMD) {
		z(e[q], "onmousedown", aa, true);
		e[q].docMD = true
	}
	if (!h[q].docMD) {
		z(h[q], "onmousedown", aa, true);
		h[q].docMD = true
	}
	z(e, "onunload", function() {
		if ($dp.dd) {
			o($dp.dd, "none")
		}
	});

	function ac() {
		try {
			h[q], h.$dp = h.$dp || {}
		} catch (c) {
			h = e;
			$dp = $dp || {}
		}
		var a = {
			win: e,
			$: function(A) {
				return (typeof A == "string") ? e[q].getElementById(A) : A
			},
			$D: function(B, A) {
				return this.$DV(this.$(B).value, A)
			},
			$DV: function(E, F) {
				if (E != "") {
					this.dt = $dp.cal.splitDate(E, $dp.cal.dateFmt);
					if (F) {
						for (var H in F) {
							if (this.dt[H] === undefined) {
								this.errMsg = "invalid property:" + H
							} else {
								this.dt[H] += F[H];
								if (H == "M") {
									var G = F.M > 0 ? 1 : 0,
										D = new Date(this.dt.y, this.dt.M, 0).getDate();
									this.dt.d = Math.min(D + G, this.dt.d)
								}
							}
						}
					}
					if (this.dt.refresh()) {
						return this.dt
					}
				}
				return ""
			},
			show: function() {
				var C = h[q].getElementsByTagName("div"),
					E = 100000;
				for (var F = 0; F < C.length; F++) {
					var D = parseInt(C[F].style.zIndex);
					if (D > E) {
						E = D
					}
				}
				this.dd.style.zIndex = E + 2;
				o(this.dd, "block");
				o(this.dd.firstChild, "")
			},
			unbind: function(A) {
				A = this.$(A);
				if (A.initcfg) {
					s(A, "onclick", function() {
						i(A.initcfg)
					});
					s(A, "onfocus", function() {
						i(A.initcfg)
					})
				}
			},
			hide: function() {
				o(this.dd, "none")
			},
			attachEvent: z
		};
		for (var b in a) {
			h.$dp[b] = a[b]
		}
		$dp = h.$dp
	}

	function z(E, b, a, c) {
		if (E.addEventListener) {
			var D = b.replace(/on/, "");
			a._ieEmuEventHandler = function(A) {
				return a(A)
			};
			E.addEventListener(D, a._ieEmuEventHandler, c)
		} else {
			E.attachEvent(b, a)
		}
	}

	function s(a, c, b) {
		if (a.removeEventListener) {
			var C = c.replace(/on/, "");
			b._ieEmuEventHandler = function(A) {
				return b(A)
			};
			a.removeEventListener(C, b._ieEmuEventHandler, false)
		} else {
			a.detachEvent(c, b)
		}
	}

	function ag(b, c, a) {
		if (typeof b != typeof c) {
			return false
		}
		if (typeof b == "object") {
			if (!a) {
				for (var C in b) {
					if (typeof c[C] == "undefined") {
						return false
					}
					if (!ag(b[C], c[C], true)) {
						return false
					}
				}
			}
			return true
		} else {
			if (typeof b == "function" && typeof c == "function") {
				return b.toString() == c.toString()
			} else {
				return b == c
			}
		}
	}

	function u() {
		var b, a, c = e[q][ab]("script");
		for (var C = 0; C < c.length; C++) {
			b = c[C].getAttribute("src") || "";
			b = b.substr(0, b.toLowerCase().indexOf("wdatepicker.js"));
			a = b.lastIndexOf("/");
			if (a > 0) {
				b = b.substring(0, a + 1)
			}
			if (b) {
				break
			}
		}
		return b
	}

	function t(a, c, E) {
		var C = e[q][ab]("HEAD").item(0),
			b = e[q].createElement("link");
		if (C) {
			b.href = a;
			b.rel = "stylesheet";
			b.type = "text/css";
			if (c) {
				b.title = c
			}
			if (E) {
				b.charset = E
			}
			C.appendChild(b)
		}
	}

	function y(G) {
		G = G || h;
		var a = 0,
			b = 0;
		while (G != h) {
			var H = G.parent[q][ab]("iframe");
			for (var c = 0; c < H.length; c++) {
				try {
					if (H[c].contentWindow == G) {
						var C = g(H[c]);
						a += C.left;
						b += C.top;
						break
					}
				} catch (I) {}
			}
			G = G.parent
		}
		return {
			leftM: a,
			topM: b
		}
	}

	function g(O, P) {
		if (O.getBoundingClientRect) {
			return O.getBoundingClientRect()
		} else {
			var J = {
					ROOT_TAG: /^body|html$/i,
					OP_SCROLL: /^(?:inline|table-row)$/i
				},
				Q = false,
				L = null,
				N = O.offsetTop,
				M = O.offsetLeft,
				a = O.offsetWidth,
				c = O.offsetHeight,
				b = O.offsetParent;
			if (b != O) {
				while (b) {
					M += b.offsetLeft;
					N += b.offsetTop;
					if (m(b, "position").toLowerCase() == "fixed") {
						Q = true
					} else {
						if (b.tagName.toLowerCase() == "body") {
							L = b.ownerDocument.defaultView
						}
					}
					b = b.offsetParent
				}
			}
			b = O.parentNode;
			while (b.tagName && !J.ROOT_TAG.test(b.tagName)) {
				if (b.scrollTop || b.scrollLeft) {
					if (!J.OP_SCROLL.test(o(b))) {
						if (!ae || b.style.overflow !== "visible") {
							M -= b.scrollLeft;
							N -= b.scrollTop
						}
					}
				}
				b = b.parentNode
			}
			if (!Q) {
				var K = af(L);
				M -= K.left;
				N -= K.top
			}
			a += M;
			c += N;
			return {
				left: M,
				top: N,
				right: a,
				bottom: c
			}
		}
	}

	function r(c) {
		c = c || h;
		var C = c[q],
			a = (c.innerWidth) ? c.innerWidth : (C[w] && C[w].clientWidth) ? C[w].clientWidth : C.body.offsetWidth,
			b = (c.innerHeight) ? c.innerHeight : (C[w] && C[w].clientHeight) ? C[w].clientHeight : C.body.offsetHeight;
		return {
			width: a,
			height: b
		}
	}

	function af(c) {
		c = c || h;
		var C = c[q],
			a = C[w],
			b = C.body;
		C = (a && a.scrollTop != null && (a.scrollTop > b.scrollTop || a.scrollLeft > b.scrollLeft)) ? a : b;
		return {
			top: C.scrollTop,
			left: C.scrollLeft
		}
	}

	function aa(b) {
		try {
			var a = b ? (b.srcElement || b.target) : null;
			if ($dp.cal && !$dp.eCont && $dp.dd && a != $dp.el && $dp.dd.style.display == "block") {
				$dp.cal.close()
			}
		} catch (b) {}
	}

	function d() {
		$dp.status = 2
	}
	var n, ah;

	function i(c, M) {
		if (!$dp) {
			return
		}
		ac();
		var b = {};
		for (var E in c) {
			b[E] = c[E]
		}
		for (E in k) {
			if (E.substring(0, 1) != "$" && b[E] === undefined) {
				b[E] = k[E]
			}
		}
		if (M) {
			if (!B()) {
				ah = ah || setInterval(function() {
					if (h[q].readyState == "complete") {
						clearInterval(ah)
					}
					i(null, true)
				}, 50);
				return
			}
			if ($dp.status == 0) {
				$dp.status = 1;
				b.el = j;
				v(b, true)
			} else {
				return
			}
		} else {
			if (b.eCont) {
				b.eCont = $dp.$(b.eCont);
				b.el = j;
				b.autoPickDate = true;
				b.qsEnabled = false;
				v(b)
			} else {
				if (k.$preLoad && $dp.status != 2) {
					return
				}
				var G = I();
				if (e.event === G || G) {
					b.srcEl = G.srcElement || G.target;
					G.cancelBubble = true
				}
				b.el = b.el = $dp.$(b.el || b.srcEl);
				if (!b.el || b.el.My97Mark === true || b.el.disabled || ($dp.dd && o($dp.dd) != "none" && $dp.dd.style.left != "-970px")) {
					try {
						if (b.el.My97Mark) {
							b.el.My97Mark = false
						}
					} catch (a) {}
					return
				}
				if (G && b.el.nodeType == 1 && !ag(b.el.initcfg, c)) {
					$dp.unbind(b.el);
					z(b.el, G.type == "focus" ? "onclick" : "onfocus", function() {
						i(c)
					});
					b.el.initcfg = c
				}
				v(b)
			}
		}

		function B() {
			if (l && h != e && h[q].readyState != "complete") {
				return false
			}
			return true
		}

		function I() {
			if (x) {
				func = I.caller;
				while (func != null) {
					var A = func.arguments[0];
					if (A && (A + "").indexOf("Event") >= 0) {
						return A
					}
					func = func.caller
				}
				return null
			}
			return event
		}
	}

	function m(a, b) {
		return a.currentStyle ? a.currentStyle[b] : document.defaultView.getComputedStyle(a, false)[b]
	}

	function o(a, b) {
		if (a) {
			if (b != null) {
				a.style.display = b
			} else {
				return m(a, "display")
			}
		}
	}

	function v(b, a) {
		var A = b.el ? b.el.nodeName : "INPUT";
		if (a || b.eCont || new RegExp(/input|textarea|div|span|p|a/ig).test(A)) {
			b.elProp = A == "INPUT" ? "value" : "innerHTML"
		} else {
			return
		}
		if (b.lang == "auto") {
			b.lang = l ? navigator.browserLanguage.toLowerCase() : navigator.language.toLowerCase()
		}
		if (!b.eCont) {
			for (var F in b) {
				$dp[F] = b[F]
			}
		}
		if (!$dp.dd || b.eCont || ($dp.dd && (b.getRealLang().name != $dp.dd.lang || b.skin != $dp.dd.skin))) {
			if (b.eCont) {
				c(b.eCont, b)
			} else {
				$dp.dd = h[q].createElement("DIV");
				$dp.dd.style.cssText = "position:absolute";
				h[q].body.appendChild($dp.dd);
				c($dp.dd, b);
				if (a) {
					$dp.dd.style.left = $dp.dd.style.top = "-970px"
				} else {
					$dp.show();
					H($dp)
				}
			}
		} else {
			if ($dp.cal) {
				$dp.show();
				$dp.cal.init();
				if (!$dp.eCont) {
					H($dp)
				}
			}
		}

		function c(O, P) {
			var Q = h[q].domain,
				U = false,
				T = '<iframe hideFocus=true width=9 height=7 frameborder=0 border=0 scrolling=no src="about:blank"></iframe>';
			O.innerHTML = T;
			var S = k.$langList,
				B = k.$skinList,
				R;
			try {
				R = O.lastChild.contentWindow[q]
			} catch (V) {
				U = true;
				O.removeChild(O.lastChild);
				var N = h[q].createElement("iframe");
				N.hideFocus = true;
				N.frameBorder = 0;
				N.scrolling = "no";
				N.src = "javascript:(function(){var d=document;d.open();d.domain='" + Q + "';})()";
				O.appendChild(N);
				setTimeout(function() {
					R = O.lastChild.contentWindow[q];
					M()
				}, 97);
				return
			}
			M();

			function M() {
				var D = P.getRealLang();
				O.lang = D.name;
				O.skin = P.skin;
				var E = ["<head><script>", "", "var doc=document, $d, $dp, $cfg=doc.cfg, $pdp = parent.$dp, $dt, $tdt, $sdt, $lastInput, $IE=$pdp.ie, $FF = $pdp.ff,$OPERA=$pdp.opera, $ny, $cMark = false;", "if($cfg.eCont){$dp = {};for(var p in $pdp)$dp[p]=$pdp[p];}else{$dp=$pdp;};for(var p in $cfg){$dp[p]=$cfg[p];}", "doc.oncontextmenu=function(){try{$c._fillQS(!$dp.has.d,1);showB($d.qsDivSel);}catch(e){};return false;};", "<\/script><script src=js/WDatePicker/lang/zh-cn.js charset=", D.charset, "><\/script>"];
				if (U) {
					E[1] = 'document.domain="' + Q + '";'
				}
				for (var G = 0; G < B.length; G++) {
					if (B[G].name == P.skin) {
						E.push('<link rel="stylesheet" type="text/css" href="js/WDatePicker/skin/default/datepicker.css" charset="' + B[G].charset + '"/>')
					}
				}
				E.push('<script src="js/WDatePicker/calendar.js"><\/script>');
				E.push('</head><body leftmargin="0" topmargin="0" tabindex=0></body></html>');
				E.push("<script>var t;t=t||setInterval(function(){if(doc.ready){new My97DP();$cfg.onload();$c.autoSize();$cfg.setPos($dp);clearInterval(t);}},20);<\/script>");
				P.setPos = H;
				P.onload = d;
				R.write("<html>");
				R.cfg = P;
				R.write(E.join(""));
				R.close()
			}
		}

		function H(P) {
			var S = P.position.left,
				L = P.position.top,
				K = P.el;
			if (K == j) {
				return
			}
			if (K != P.srcEl && (o(K) == "none" || K.type == "hidden")) {
				K = P.srcEl
			}
			var Q = g(K),
				O = y(e),
				U = r(h),
				M = af(h),
				T = $dp.dd.offsetHeight,
				N = $dp.dd.offsetWidth;
			if (isNaN(L)) {
				L = 0
			}
			if ((O.topM + Q.bottom + T > U.height) && (O.topM + Q.top - T > 0)) {
				L += M.top + O.topM + Q.top - T - 2
			} else {
				L += M.top + O.topM + Q.bottom;
				var R = L - M.top + T - U.height;
				if (R > 0) {
					L -= R
				}
			}
			if (isNaN(S)) {
				S = 0
			}
			S += M.left + Math.min(O.leftM + Q.left, U.width - N - 5) - (l ? 2 : 0);
			P.dd.style.top = L + "px";
			P.dd.style.left = S + "px"
		}
	}
})();